import { getUserInfo } from "../../utils/common";
var Fly = require("flyio/dist/npm/fly");
// Node 入口
// var Fly=require("flyio/src/node")
var fly = new Fly();

//添加拦截器
// let token: string | undefined = getUserInfo("randomData");
// fly.interceptors.request.use((config, promise) => {
//   config.headers["Content-Type"] = "application/x-www-form-urlencoded"; //给所有请求添加自定义header
//   config.headers["Authorization"] = token;
//   return config;
// });
//添加请求拦截器
fly.interceptors.request.use((request) => {
  let token: string | undefined = getUserInfo("randomData");
  //给所有请求添加自定义header
  request.headers["Authorization"] = token;
  //打印出请求体
  console.log(request.body);
  //终止请求
  //var err=new Error("xxx")
  //err.request=request
  //return Promise.reject(new Error(""))

  //可以显式返回request, 也可以不返回，没有返回值时拦截器中默认返回request
  return request;
});
export default fly;
